﻿using AzureContrib.WindowsAzure.Diagnostics;
using AzureContrib.WindowsAzure.ServiceRuntime;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Rhino.Mocks;

namespace AzureContrib.WindowsAzure.Tests.Diagnostics
{
	[TestClass]
	public class ServiceBusTraceListenerTests
	{
		[TestMethod]
		public void Create()
		{
			IRoleEnvironment roleEnvironment = MockRepository.GenerateMock<IRoleEnvironment>();

			var role = MockRepository.GenerateMock<IRole>();
			role.Expect(r => r.Name).Return("The name of the role.");

			var roleInstance = MockRepository.GenerateMock<IRoleInstance>();
			roleInstance.Expect(re => re.Role).Return(role);
			roleInstance.Expect(re => re.Id).Return("This is the role instance id.");

			roleEnvironment.Expect(re => re.CurrentRoleInstance).Return(roleInstance).Repeat.Twice();
			roleEnvironment.Expect(re => re.DeploymentId).Return("This is the deployment id.");

			string test;
			roleEnvironment.Expect(re => re.TryGetConfigurationSettingValue(ServiceBusTraceListener.ServiceBusIssuerKeySettingName, out test)).OutRef(new[] { "the value ServiceBusIssuerKeySettingName" }).Return(true);
			roleEnvironment.Expect(re => re.TryGetConfigurationSettingValue(ServiceBusTraceListener.ServiceBusIssuerNameSettingName, out test)).OutRef(new[] { "the value ServiceBusIssuerNameSettingName" }).Return(true);
			roleEnvironment.Expect(re => re.TryGetConfigurationSettingValue(ServiceBusTraceListener.ServiceBusNameSpaceSettingName, out test)).OutRef(new[] { "servicebusnamespace" }).Return(true);
			roleEnvironment.Expect(re => re.TryGetConfigurationSettingValue(ServiceBusTraceListener.ServiceBusOperationTimeOutSettingSettingName, out test)).OutRef(new[] { "42" }).Return(true);
			roleEnvironment.Expect(re => re.TryGetConfigurationSettingValue(ServiceBusTraceListener.ServiceBusTopicSettingName, out test)).OutRef(new[] { "the value ServiceBusTopicSettingName" }).Return(true);

			new ServiceBusTraceListener(roleEnvironment);

			role.VerifyAllExpectations();
			roleInstance.VerifyAllExpectations();
			roleEnvironment.VerifyAllExpectations();
		}
	}
}